package controllers

type SQLConfig struct {
	Schema 		string
	User 		string
	Password 	string
	DBName		string
}
// DBNameType
type DBNameType int
const (
	HHLABManaggment DBNameType = iota
)
// TableNameType
type TableNameType int
const (
	HHUser TableNameType = iota
	HHDeviceInfo
	HHGatewayBandHistory
	HHGatewayBandStatus
	HHDeviceStateHistory
	HHDeviceState
	HHHistoryData
	HHDeviceAlarm
	HHAdministrator
)
var DBIndex = map[DBNameType]string {
	HHLABManaggment: "HHLAB_managgment",
}
var TableIndex = map[TableNameType]string {
	HHUser					: "hh_user",
	HHDeviceInfo  			: "hh_device_info",
	HHGatewayBandHistory  	: "hh_gateway_band_history",
	HHGatewayBandStatus	  	: "hh_gateway_band_status",
	HHDeviceStateHistory  	: "hh_device_state_history",
	HHDeviceState			: "hh_device_state",
	HHHistoryData			: "hh_history_data",
	HHDeviceAlarm			: "hh_device_alarm",
}

// QueryType
type QueryType int
const (
	// todo define insert type
	InsertHistoryData QueryType = iota
	InsertDeviceAlarm
	InsertAuthorityData
	InsertDeviceInfo
	InsertUserInfo
	InsertDeviceStateHistory
	InsertDeviceState
	InsertGatewayBandStatus
	InsertGatewayBandHistory


)
var QueryTemplate = map[QueryType]string{
	InsertHistoryData: "insert into " + TableIndex[HHHistoryData] + " (gateway_id, upload_time, device_type, temp," +
		" speed, display_time, status, mode, lossElecMem) values (?, ?, ?, ?, ?, ?, ?, ?, ?);",
	InsertDeviceAlarm: "insert into " + TableIndex[HHDeviceAlarm] + " (gateway_id, device_type, alarm_date," +
		" inner_sensor_err, inner_sensor_temp_alarm, external_sensor_err, external_sensor_over_temp," +
		" mechanical_limit_temp_over_temp, mechanical_limit_sensor_err, motor_stalling, external_sensor_drop, end_of_time, " +
		"external_sensor_not_plugged) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
	InsertAuthorityData: "insert into " + TableIndex[HHAdministrator] + "(username, password, salt) values (?, ?, ?);",
}


func NewMySQLConfig() *SQLConfig {
	return &SQLConfig{
		Schema:	"mysql",
		User:	"root",
		Password:	"123456",
		DBName:	DBIndex[HHLABManaggment],
	}
}